package main

import (
	"fmt"
	"github.com/mcuadros/go-defaults"
	toml "github.com/pelletier/go-toml"
	"log"
)

func main() {
	type DownloadConfiguration struct {
		Directory string `toml:"directory" default:"/var/lib/cds-engine" json:"directory" comment:"this directory contains projecttemplate binaries. If it's empty, projecttemplate will download binaries from GitHub (property downloadFromGitHub) or from an artifactory instance (property artifactory) to it"`
	}
	type ApiConfiguration struct {
		Name string `toml:"name" comment:"Name of this projecttemplate API Service\n Enter a name to enable this service" json:"name"`
		URL  struct {
			API string `toml:"api" default:"http://localhost:8081" json:"api"`
			UI  string `toml:"ui" default:"http://localhost:8080" json:"ui"`
		} `toml:"url" comment:"#####################\n projecttemplate URLs Settings \n####################" json:"url"`
		//HTTP     service.HTTPRouterConfiguration `toml:"http" json:"http"`
		//Database database.DBConfiguration        `toml:"database" comment:"################################\n Postgresql Database settings \n###############################" json:"database"`
		Cache struct {
			TTL   int `toml:"ttl" default:"60" json:"ttl"`
			Redis struct {
				Host     string `toml:"host" default:"localhost:6379" comment:"If your want to use a redis-sentinel based cluster, follow this syntax! <clustername>@sentinel1:26379,sentinel2:26379,sentinel3:26379" json:"host"`
				Password string `toml:"password" json:"-"`
				DbIndex  int    `toml:"dbindex" default:"0" json:"dbindex"`
			} `toml:"redis" comment:"Connect projecttemplate to a redis cache If you more than one projecttemplate instance and to avoid losing data at startup" json:"redis"`
		} `toml:"cache" comment:"######################\n projecttemplate Cache Settings \n#####################" json:"cache"`
		//Download            *download.Configuration `toml:"download" json:"download"`
		InternalServiceMesh struct {
			RequestSecondsTimeout int  `toml:"requestSecondsTimeout" json:"requestSecondsTimeout" default:"60"`
			InsecureSkipVerifyTLS bool `toml:"insecureSkipVerifyTLS" json:"insecureSkipVerifyTLS" default:"false"`
		} `toml:"internalServiceMesh" json:"internalServiceMesh"`
		Auth struct {
			TokenDefaultDuration         int64  `toml:"tokenDefaultDuration" default:"30" comment:"The default duration of a token (in days)" json:"tokenDefaultDuration"`
			TokenOverlapDefaultDuration  string `toml:"tokenOverlapDefaultDuration" default:"24h" comment:"The default overlap duration when a token is regen" json:"tokenOverlapDefaultDuration"`
			DefaultGroup                 string `toml:"defaultGroup" default:"" comment:"The default group is the group in which every new user will be granted at signup" json:"defaultGroup"`
			DisableAddUserInDefaultGroup bool   `toml:"disableAddUserInDefaultGroup" default:"false" comment:"If false, user are automatically added in the default group" json:"disableAddUserInDefaultGroup"`
			RSAPrivateKey                string `toml:"rsaPrivateKey" default:"" comment:"The RSA Private Key used to sign and verify the JWT Tokens issued by the API \nThis is mandatory." json:"-"`
			//RSAPrivateKeys               []authentication.KeyConfig `toml:"rsaPrivateKeys" default:"" comment:"RSA Private Keys used to sign and verify the JWT Tokens issued by the API \nThis is mandatory." json:"-" mapstructure:"rsaPrivateKeys"`
			//AllowedOrganizations         sdk.StringSlice            `toml:"allowedOrganizations" comment:"The list of allowed organizations for projecttemplate users, let empty to authorize all organizations." json:"allowedOrganizations"`
		} `toml:"auth" comment:"##############################\n projecttemplate Authentication Settings# \n#############################" json:"auth"`
		SMTP struct {
			Disable               bool   `toml:"disable" default:"true" json:"disable" comment:"Set to false to enable the internal SMTP client. If false, emails will be displayed in projecttemplate API Log."`
			Host                  string `toml:"host" json:"host" comment:"smtp host"`
			Port                  string `toml:"port" json:"port" comment:"smtp port"`
			ModeTLS               string `toml:"modeTLS" json:"modeTLS" default:"" comment:"possible values: empty, tls, starttls"`
			InsecureSkipVerifyTLS bool   `toml:"insecureSkipVerifyTLS" json:"insecureSkipVerifyTLS" default:"false" comment:"skip TLS verification with TLS / StartTLS mode"`
			User                  string `toml:"user" json:"user" comment:"smtp username"`
			Password              string `toml:"password" json:"-" comment:"smtp password"`
			From                  string `toml:"from" default:"no-reply@cds.local" json:"from" comment:"smtp from"`
		} `toml:"smtp" comment:"#####################\n# projecttemplate SMTP Settings \n####################" json:"smtp"`
		DefaultOS   string `toml:"defaultOS" default:"linux" comment:"if no model and os/arch is specified in your job's requirements then spawn worker on this operating system (example: darwin, freebsd, linux, windows)" json:"defaultOS"`
		DefaultArch string `toml:"defaultArch" default:"amd64" comment:"if no model and no os/arch is specified in your job's requirements then spawn worker on this architecture (example: amd64, arm, 386)" json:"defaultArch"`
		Log         struct {
			StepMaxSize    int64 `toml:"stepMaxSize" default:"15728640" comment:"Max step logs size in bytes (default: 15MB)" json:"stepMaxSize"`
			ServiceMaxSize int64 `toml:"serviceMaxSize" default:"15728640" comment:"Max service logs size in bytes (default: 15MB)" json:"serviceMaxSize"`
		} `toml:"log" json:"log" comment:"###########################\n Log settings.\n##########################"`
		Help struct {
			Content string `toml:"content" comment:"Help Content. Warning: this message could be view by anonymous user. Markdown accepted." json:"content" default:""`
			Error   string `toml:"error" comment:"Help displayed to user on each error. Warning: this message could be view by anonymous user. Markdown accepted." json:"error" default:""`
		} `toml:"help" comment:"######################\n 'Help' informations \n######################" json:"help"`
	}
	type Configuration struct {
		Log struct {
			Level   string `toml:"level" default:"warning" comment:"Log Level: debug, info, warning, notice, error" json:"level"`
			Format  string `toml:"format" default:"text" comment:"Stdout format: text, json, discard" json:"format"`
			Graylog struct {
				Host       string `toml:"host" comment:"Example: thot.ovh.com" json:"host"`
				Port       int    `toml:"port" comment:"Example: 12202" json:"port"`
				Protocol   string `toml:"protocol" default:"tcp" comment:"tcp or udp" json:"protocol"`
				ExtraKey   string `toml:"extraKey" comment:"Example: X-OVH-TOKEN. You can use many keys: aaa,bbb" json:"extraKey"`
				ExtraValue string `toml:"extraValue" comment:"value for extraKey field. For many keys: valueaaa,valuebbb" json:"extraValue"`
			} `toml:"graylog"`
		} `toml:"log" comment:"#####################\n Logs Settings \n####################"`
		API      *ApiConfiguration      `toml:"api" comment:"#####################\n API Configuration \n####################" json:"api"`
		Download *DownloadConfiguration `toml:"download" comment:"#####################\n Download Configuration \n####################" json:"download"`
	}

	config := &Configuration{}
	defaults.SetDefaults(config)
	config.Download = &DownloadConfiguration{}
	defaults.SetDefaults(config.Download)
	config.API = &ApiConfiguration{}
	defaults.SetDefaults(config.API)
	b, err := toml.Marshal(config)
	if err != nil {
		log.Fatal(err)
	}
	strb := string(b)
	fmt.Println(strb)
}
